import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'
Vue.use(VueRouter);

// 重写push
let originPush = VueRouter.prototype.push
let originReplace = VueRouter.prototype.replace

//第一个参数：告诉原来的push方法跳转目标
//第二个参数：成功回调
//第三个参数：失败回调
VueRouter.prototype.push = function(location,resolve,reject){
  if (resolve && reject) {
    originPush.call(this,location,resolve,reject)
  }else{
  originPush.call(this,location,()=>{},()=>{})
  }
}

//重写路由
VueRouter.prototype.replace = function(location,resolve,reject){
  if (resolve && reject) {
    originReplace.call(this,location,resolve,reject)
  }else{
  originReplace.call(this,location,()=>{},()=>{})
  }
}


const router = new VueRouter({
  routes,
  //路由滚动行为
  scrollBehavior(to,from,savedPosition){
    return {x:0,y:0}
  }


})

export default router